// pages/test/message/index.js
var App = getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		list: '',
		nums:0,
		page:2
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		var that = this;
		that.getmessage();
	},
	gotest:function(){
		wx.switchTab({
			url: '../../my/indexPage/index',
		})
	},
	getmessage: function () {
		var that = this;
		App.ajax.ajax('userInfo.do?method=testScheduleList', {
			JSESSIONID: wx.getStorageSync('JSESSIONID'),
			page: 1,
			limit: 6,
			status: "已完成",
		}, function (res) {
			for(var i=0;i<res.data.items.length;i++){
				res.data.items[i].register_date = res.data.items[i].register_date.substring(0,10);
			}
			 that.setData({
				 list: res.data.items
			 })
		})
		console.log(that.data.list)
	},

	testdetail: function (e) {
		var id = e.currentTarget.dataset.id;
		console.log(id);
		var that = this;
		wx.navigateTo({
			url: '../../my/trainDetail/index?id=' + id,
		})
	},
	getpage: function (page) {
		var that = this;
		if (that.data.page > that.data.nums) {
			wx.showToast({
				title: '已加载全部',
				icon: 'none'
			})
		}
		else {
			App.ajax.ajax('userInfo.do?method=testScheduleList', {
				page: page,
				JSESSIONID: wx.getStorageSync('JSESSIONID'),
				limit: 6
			}, function (res) {
				for (var i = 0; i < res.data.items.length; i++) {
					res.data.items[i].register_date = (res.data.items[i].register_date).substring(0, 10);
				}
				var list = that.data.list;
				var allData = list.concat(res.data.items);
				that.setData({
					list: allData,
					page: that.data.page + 1
				})
			})
		}
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		var that = this;
		var page = that.data.page;
		that.getpage(page);
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})